import { defineStore } from "pinia";
import { Names } from "../../store-namespace";
import { _get, _post, _put, _delete, http } from "@/utils/axios";
import { FactoryStation } from "@/api/backend/index";
import { handleTree, handleRegionIds } from "@/utils/common";

export const useFactoryStation = defineStore(Names.factoryS, {
  state: () => {
    return {
      single: {},
      originData: {},
    };
  },
  getters: {},
  actions: {
    //工位信息导入excel文件
    importExcel(data: any) {
      return new Promise((resolve, reject) => {
        _post(FactoryStation + "/import", data, "formData", "")
          .then((res) => {
            console.log("导入excel文件", res);
            resolve(res as any);
          })
          .catch((err) => {
            console.log(err);
          });
      });
    },
    //获取工作中心树型数据
    getStationByRole() {
      return new Promise((resolve, reject) => {
        _get(FactoryStation + "/list", {}, "json", "")
          .then(async (res: any) => {
            this.originData = res.rows; //原始树形结构数据
            resolve(res.rows);
          })
          .catch((err) => {
            reject(err);
          });
      });
    },
  },
});
